using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Ent.Voice.Nomination;
using StarRating;

public partial class Controls_EntryStats : System.Web.UI.UserControl
{
    private Entry _entry;
    public Entry Entry
    {
        get { return _entry; }
        set { _entry = value; }
    }
    public Controls_EntryStats()
    {
        this.PreRender += new EventHandler(Controls_EntryStats_PreRender);
    }

    void Controls_EntryStats_PreRender(object sender, EventArgs e)
    {
        if (_entry == null)
            return;
        tblStats.Width = Unit.Percentage(100);
        tblStats.CssClass = "text10";
        tblStats.CellPadding = 0;
        tblStats.CellSpacing = 0;
        TableRow tr = new TableRow();
        TableCell tc = new TableCell();
        tc.ColumnSpan = 2;
        tc.CssClass = "generaltd";
        tc.VerticalAlign = VerticalAlign.Top;
        tc.CssClass = "header1";
        tc.Text = "<img src='" + ConfigurationManager.AppSettings["BaseUrl"] + "/Images/dj/stats.gif' style='width:15px' alt='Stats' title='Stats' />&nbsp;" +
            ResourceHelper.Get("LBL_Stats");
        tr.Cells.Add(tc);
        tblStats.Rows.Add(tr);
        tr = new TableRow();
        tc = new TableCell();
        tc.ColumnSpan = 2;
        tc.CssClass = "generaltd";
        tc.VerticalAlign = VerticalAlign.Top;
        Label lbl = new Label();
        lbl.Text = "<b>" + ResourceHelper.Get("LBL_Rank") + "</b>&nbsp;";
        tc.Controls.Add(lbl);
        StarRating.StarRating sr = new StarRating.StarRating();
        sr.Mode = ActionMode.Javascript;
        sr.JavaScript = "javascript:votewindow=dhtmlmodal.open('RuleSetBox', 'iframe', '" + ConfigurationManager.AppSettings["BaseUrl"] + "/ShowVote.aspx?id=" + _entry.Id.ToString() + "&name=" + _entry.Title + "&sel=1', 'Vote Comments', 'width=560px,height=410px,center=1,resize=0,scrolling=0');";
        if (_entry.Attended != 0)
            sr.Value = Convert.ToInt32((_entry.Points + (5 * _entry.Votes)) / _entry.Attended);
        sr.OnImage = ConfigurationManager.AppSettings["BaseUrl"] + "/Images/dj/on.gif";
        sr.OffImage = ConfigurationManager.AppSettings["BaseUrl"] + "/Images/dj/off.gif";
        tc.Controls.Add(sr);
        lbl = new Label();
        if (_entry.Attended != 0)
            lbl.Text = " [" + Convert.ToString(Math.Round(((_entry.Points + (5.00 * _entry.Votes)) / _entry.Attended), 2)) + "]";
        else
            lbl.Text = " [0]";
        tc.Controls.Add(lbl);
        tr.Cells.Add(tc);
        tblStats.Rows.Add(tr);
        tr = new TableRow();
        tr.Cells.Add(CreateTableCell("LBL_Points", _entry.Points.ToString()));
        tr.Cells.Add(CreateTableCell("LBL_Votes", _entry.Votes.ToString()));
        tblStats.Rows.Add(tr);
        tr = new TableRow();
        tr.Cells.Add(CreateTableCell("LBL_Attended", _entry.Attended.ToString()));
        tr.Cells.Add(CreateTableCell("LBL_Views", _entry.Views.ToString()));
        tblStats.Rows.Add(tr);
    }
    private void SetJavascript()
    {
        string jScript = "<script type=\"text/javascript\">";
        jScript += "function ShowRules() {";
        jScript += "\r\nvar sel='';";
        jScript += "\r\n";
        jScript += "\r\nreturn false;";
        jScript += "\r\n}";
        jScript += "\r\n</script>";
        Page.RegisterClientScriptBlock("script_name", jScript);
    }
    private TableCell CreateTableCell(string title, string value)
    {
        TableCell tc = new TableCell();
        tc.CssClass = "generaltd";
        tc.VerticalAlign = VerticalAlign.Top;
        tc.Text = "<b>" + ResourceHelper.Get(title) + "</b>&nbsp;";
        tc.Text += value;
        return tc;
    }
    protected void Page_Load(object sender, EventArgs e)
    {
       
    }
}
